package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.analyse.AnalyseNews;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.RegexUtils;
import com.kdtech.utils.StringUtils;

/**
 * <电视台 - 萧山电视台> 解析类
 *
 * @author KK
 *
 */
public class XianghunetAnalyse implements AnalyseNews {
	
	public boolean isDetailPage(String url) {
		String[] regex = {
				"http://.*.xianghunet.com/video/view/[0-9]+.html",
				"http://.*.xianghunet.com/video-[0-9]+.html",
				};

		return RegexUtils.matchAny(url,regex);
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		if (urlMeta.getHtml() == null) {
		}
		String htmltxt = urlMeta.getHtml();
		String url = urlMeta.getUrl();

		String title = null;
		Long date = null;
		String desc = null;
		String dateStr = null;
		String commnetNum = null;
		String clickNum = null;
		String updateUrl = null;
		Document doc = Jsoup.parse(htmltxt);

		title =     doc.select("title").text();
		title = StringUtils.substringBefore(title, "_");
		date = DateUtils.matchDate(doc.select("div.time,div.update_time").text());
		desc = doc.select("div#intro").text();
		if(StringUtils.isBlank(desc)){
			desc = doc.select("span#allintro").text();
			if(desc.startsWith("简介：")){
				desc = desc.substring("简介：".length());
			}
		}
			NewsMeta news = new NewsMeta();
			news.setUrl(url);
			news.setType(2);
			news.setTitle(StringUtils.trimSpace(title));
			news.setContent(desc);
			news.setDate(date);
			return news;

	}

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}

	

	
}
